/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */
package com.ykht.proj.coupon.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ykht.proj.admin.api.entity.SysUser;
import com.ykht.proj.admin.api.feign.RemoteUserService;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.Enum.DistributionTypeEnum;
import com.ykht.proj.coupon.Enum.UserTypeEnum;
import com.ykht.proj.coupon.entity.*;
import com.ykht.proj.coupon.mapper.CnShopMapper;
import com.ykht.proj.coupon.mapper.FxRewardMapper;
import com.ykht.proj.coupon.service.*;
import com.ykht.proj.coupon.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 服务员奖励记录表(待定)
 *
 * @author proj code generator
 * @date 2021-02-01 19:00:17
 */
@Service
@Slf4j
@SuppressWarnings("all")
public class  FxRewardServiceImpl extends ServiceImpl<FxRewardMapper, FxReward> implements FxRewardService {

	@Resource
	private FxRewardMapper fxRewardMapper;
	@Resource
	private CnShopMapper cnShopMapper;
	@Resource
	private FxShopMoneyFlowService fxShopMoneyFlowService;
	@Resource
	private RemoteUserService remoteUserService;

	@Resource
	private FxConfRewardService fxConfRewardService;
	@Resource
	private FxConfRewardBaseGlobelService fxConfRewardBaseGlobelService;
	@Resource
	private CnUserExtService cnUserExtService;

	/**
	 * 分销明细 分页查询
	 *
	 * @param page
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public IPage<FxRewardVo> findPage(Page page, FxRewardVo fxRewardVo) {
		return fxRewardMapper.findPage(page, fxRewardVo);
	}

	/**
	 * 获取 分销明细 统计金额
	 *
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public FxRewardVo getSumByMoney(FxRewardVo fxRewardVo) {
		return fxRewardMapper.getSumByMoney(fxRewardVo);
	}

	/**
	 * 获取饭友详情 的 核销明细 分页
	 *
	 * @param page
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public IPage<FxRewardVo> getWriteDetailsListPage(Page page, FxRewardVo fxRewardVo) {
		return fxRewardMapper.getWriteDetailsListPage(page, fxRewardVo);
	}

	/**
	 * 获取饭友详情 的 核销明细 统计（核销佣金 和 核销次数）
	 *
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public FxRewardVo getWriteDetailsCount(FxRewardVo fxRewardVo) {
		return fxRewardMapper.getWriteDetailsCount(fxRewardVo);
	}

	/**
	 * 饭友详情的 饭友列表 分页
	 *
	 * @param page
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public IPage<FxRewardVo> getFanYouDetailsListPage(Page page, FxRewardVo fxRewardVo) {
		return fxRewardMapper.getFanYouDetailsListPage(page, fxRewardVo);
	}


	/**b端
	 * 账户概览
	 * @param
	 * @return
	 */
	@Override
	public ZHGLVo zhgl(BaseSearchTimeVo timeVo,UserTypeIdVo userTypeIdVo) {
		optUserTypeIdVoAndBaseSearchTimeVo(timeVo,userTypeIdVo);

		ZHGLVo vo = new ZHGLVo();
		if (userTypeIdVo.getShopId()!=null){
			BigDecimal shopBalance = fxShopMoneyFlowService.shopBalance(userTypeIdVo.getShopId(),timeVo);
			//余额
			vo.setBalance(shopBalance.toString());
		}
		List<FxReward> list = this.list(Wrappers.lambdaQuery(FxReward.class)
				.select(FxReward::getType,FxReward::getMoney,FxReward::getCreateTime)
				.eq(userTypeIdVo.getShopId()!=null,FxReward::getShopId,userTypeIdVo.getShopId())
				.eq(userTypeIdVo.getBrandId()!=null,FxReward::getBrandId,userTypeIdVo.getBrandId())
				.eq(userTypeIdVo.getCompanyId()!=null,FxReward::getCompanyId,userTypeIdVo.getCompanyId())
				.ge(timeVo.getStartTime()!=null,FxReward::getCreateTime,timeVo.getStartTime())
				.le(timeVo.getEndTime()!=null,FxReward::getCreateTime,timeVo.getEndTime()));
		//奖励类型0注册1转发2核销
		BigDecimal invite = list.stream().filter(o->o.getType()== DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue()).map(FxReward::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add);
		BigDecimal forward = list.stream().filter(o->o.getType()==DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue()).map(FxReward::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add);
		BigDecimal use = list.stream().filter(o->o.getType()==DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue()).map(FxReward::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add);
		vo.setForward(forward.toString());
		vo.setUse(use.toString());
		vo.setInvite(invite.toString());
		vo.setAddUpSpend(invite.add(use).add(forward).toString());
		return vo;
	}

	private void optUserTypeIdVoAndBaseSearchTimeVo(BaseSearchTimeVo timeVo, UserTypeIdVo userTypeIdVo) {
		optTimeVo(timeVo);
		optUserTypeIdVo(userTypeIdVo);
	}

	/*public static void main(String[] args) {
		UserTypeIdVo object = new UserTypeIdVo();
		boolean flge = Objects.isNull(object);
//		BeanUtil.hasNullField(object,object.getShopId(),object.getBrandId(),object.getCompanyId());
		object.setBrandId(1l);
		flge = BeanUtil.isEmpty(object);
		System.out.println(flge);
		List<FxReward> list = new ArrayList<>();
		FxReward reward = new FxReward();
		reward.setMoney(new BigDecimal("0"));
		reward.setType(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue());
		BigDecimal invite = list.stream().filter(o->o.getType()== DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue()).map(FxReward::getMoney).reduce(BigDecimal.ZERO,BigDecimal::add);

	}*/
	/**
	 * 核销概况
	 * @param timeVo
	 * @param userTypeIdVo
	 * @return
	 */
	@Override
	public CouponUseResp couponUse(BaseSearchTimeVo timeVo,UserTypeIdVo userTypeIdVo) {

		optUserTypeIdVoAndBaseSearchTimeVo(timeVo,userTypeIdVo);

		CouponUseResp resp = new CouponUseResp();
		List<FxReward> list = this.list(Wrappers.lambdaQuery(FxReward.class)
				.eq(FxReward::getType,DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue())//核销
				.eq(userTypeIdVo.getShopId()!=null,FxReward::getShopId,userTypeIdVo.getShopId())
				.eq(userTypeIdVo.getBrandId()!=null,FxReward::getBrandId,userTypeIdVo.getBrandId())
				.eq(userTypeIdVo.getCompanyId()!=null,FxReward::getCompanyId,userTypeIdVo.getCompanyId())
				.ge(timeVo.getStartTime()!=null,FxReward::getCreateTime,timeVo.getStartTime())
				.le(timeVo.getEndTime()!=null,FxReward::getCreateTime,timeVo.getEndTime()));
		//总数量
		resp.setAllSize(list.size());
		//总金额
		BigDecimal allMoney = list.stream().map(FxReward::getUseMoney).reduce(BigDecimal.ZERO,BigDecimal::add);
		resp.setAllMoney(allMoney.toString());

		List<CouponUseResp.UseResp> useResplist = new ArrayList<>();

		//根据LocalDateTime 转换成localdate时间 分组
		Map<LocalDate,List<FxReward>> map = list.stream().collect(Collectors.groupingBy(o->o.getCreateTime().toLocalDate()));
		map.forEach((k,v)->{
			CouponUseResp.UseResp useResp = new CouponUseResp.UseResp();
			BigDecimal money = v.stream().map(FxReward::getUseMoney).reduce(BigDecimal.ZERO,BigDecimal::add);
			useResp.setMoney(money.toString());
			useResp.setSize(v.size());
			useResp.setDate(k);
			useResplist.add(useResp);
		});
		resp.setList(useResplist);
		return resp;
	}

	/**
	 * 操作时间
	 * @param timeVo
	 * @return
	 */
	public BaseSearchTimeVo optTimeVo(BaseSearchTimeVo timeVo) {
		if (timeVo.getOffsetDay()==null) return timeVo;
		if (timeVo.getOffsetDay()>0) timeVo.setOffsetDay(0);
		switch (timeVo.getOffsetDay()){
			case -1:
				timeVo.setStartTime(LocalDateTime.of(LocalDate.now().plusDays(timeVo.getOffsetDay()), LocalTime.MIN));
				timeVo.setEndTime(LocalDateTime.of(LocalDate.now().plusDays(timeVo.getOffsetDay()), LocalTime.MAX));
				return timeVo;
			default:
				timeVo.setStartTime(LocalDateTime.of(LocalDate.now().plusDays(timeVo.getOffsetDay()), LocalTime.MIN));
				timeVo.setEndTime(LocalDateTime.now());
				return timeVo;
		}
	}
	/**
	 * 根据登陆人和usertype来赋值userTypeIdVo
	 * @param userTypeIdVo
	 * @return
	 */
	private UserTypeIdVo optUserTypeIdVo(UserTypeIdVo userTypeIdVo) {
		//有id不为null说明前端传值了，不是首次进来
		if (BeanUtil.isNotEmpty(userTypeIdVo)) return userTypeIdVo;

		Integer userType = SecurityUtils.getUser().getUserType();
		Long sjId = SecurityUtils.getSjId();
		switch (UserTypeEnum.getThisByVal(userType)){
			case company:
				userTypeIdVo.setCompanyId(sjId);
				break;
			case brand:
				userTypeIdVo.setBrandId(sjId);
				break;
			case shop:
				userTypeIdVo.setShopId(sjId);
				break;
		}
		return userTypeIdVo;
	}

	@Override
	public CouponUseTopVo couponUseTop(BaseSearchTimeVo timeVo, UserTypeIdVo userTypeIdVo) {
		optUserTypeIdVoAndBaseSearchTimeVo(timeVo,userTypeIdVo);
		log.info("->开始品牌维度统计");
		CouponUseTopVo vo = new CouponUseTopVo();

		List<CouponUseTopVo.InnerCouponUseTopShopVo> shopList = new ArrayList<>();
		List<FxReward> list = this.list(Wrappers.lambdaQuery(FxReward.class)
				.eq(FxReward::getType,DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue())//核销
				.eq(userTypeIdVo.getShopId()!=null,FxReward::getShopId,userTypeIdVo.getShopId())
				.eq(userTypeIdVo.getBrandId()!=null,FxReward::getBrandId,userTypeIdVo.getBrandId())
				.eq(userTypeIdVo.getCompanyId()!=null,FxReward::getCompanyId,userTypeIdVo.getCompanyId())
				.ge(timeVo.getStartTime()!=null,FxReward::getCreateTime,timeVo.getStartTime())
				.le(timeVo.getEndTime()!=null,FxReward::getCreateTime,timeVo.getEndTime()));
		//根据门店id 分组
		Map<Long,List<FxReward>> shopMap = list.stream().collect(Collectors.groupingBy(o->o.getShopId()));
		shopMap.forEach((k,v)->{
			BigDecimal money = v.stream().map(FxReward::getUseMoney).reduce(BigDecimal.ZERO,BigDecimal::add);
			CouponUseTopVo.InnerCouponUseTopShopVo shop = new CouponUseTopVo.InnerCouponUseTopShopVo();
			shop.setMoney(money.toString());
			shop.setShopId(k);
			shopList.add(shop);
		});
		//前十个
		List<CouponUseTopVo.InnerCouponUseTopShopVo> voListTempShopTop = shopList.stream().sorted(Comparator.comparing(CouponUseTopVo.InnerCouponUseTopShopVo::getMoney).reversed()).limit(10).collect(Collectors.toList());
		if (voListTempShopTop.size()>0){
			//前十个的门店名称
			List<CnShop> tempShopList = cnShopMapper.selectList(Wrappers.lambdaQuery(CnShop.class)
					.in(CnShop::getId,voListTempShopTop.stream().map(CouponUseTopVo.InnerCouponUseTopShopVo::getShopId).collect(Collectors.toList())));
			//list根据id转map
			Map<Long,CnShop> tempShopMap = tempShopList.stream().collect(Collectors.toMap(CnShop::getId,o->o));
			//组装门店name
			voListTempShopTop.stream().forEach(o->o.setName(tempShopMap.getOrDefault(o.getShopId(),new CnShop()).getName()));
		}
		vo.setShopTopList(voListTempShopTop);

		if(SecurityUtils.getUser().getUserType()!=UserTypeEnum.company.getValue()) return vo;
		log.info("->开始品牌维度统计");

		List<CouponUseTopVo.InnerCouponUseTopBrandVo> brandList = new ArrayList<>();
		Map<Long,List<FxReward>> brandMap = list.stream().collect(Collectors.groupingBy(o->o.getBrandId()));
		brandMap.forEach((k,v)->{
			BigDecimal money = v.stream().map(FxReward::getUseMoney).reduce(BigDecimal.ZERO,BigDecimal::add);
			CouponUseTopVo.InnerCouponUseTopBrandVo brand = new CouponUseTopVo.InnerCouponUseTopBrandVo();
			brand.setMoney(money.toString());
			brand.setBrandId(k);
			brandList.add(brand);
		});
		//前十个
		List<CouponUseTopVo.InnerCouponUseTopBrandVo> voListTempBrandTop = brandList.stream().sorted(Comparator.comparing(CouponUseTopVo.InnerCouponUseTopBrandVo::getMoney).reversed()).limit(10).collect(Collectors.toList());
		if(voListTempBrandTop.size()>0){
			//前十个的品牌名称
			List<CnBrand> tempbrandList = new CnBrand().selectList(Wrappers.lambdaQuery(CnBrand.class)
					.in(CnBrand::getId,voListTempBrandTop.stream().map(CouponUseTopVo.InnerCouponUseTopBrandVo::getBrandId).collect(Collectors.toList())));

			//list根据id转map
			Map<Long,CnBrand> tempBrandMap = tempbrandList.stream().collect(Collectors.toMap(CnBrand::getId,o->o));
			//组装门店name
			voListTempBrandTop.stream().forEach(o->o.setName(tempBrandMap.getOrDefault(o.getBrandId(),new CnBrand()).getBrandName()));
		}

		vo.setBrandTopList(voListTempBrandTop);
		return vo;
	}


	/**
	 * 分销任务
	 * @param timeVo
	 * @param userTypeIdVo
	 * @return
	 */
	@Override
	public FXRWVo fxrw(BaseSearchTimeVo timeVo, UserTypeIdVo userTypeIdVo) {

		optUserTypeIdVoAndBaseSearchTimeVo(timeVo,userTypeIdVo);
		FXRWVo vo = new FXRWVo();
//		List<Map> mapList = fxRewardMapper.fxrwStatistics();
		List<FxReward> list = this.list(Wrappers.lambdaQuery(FxReward.class)
				.select(FxReward::getType,FxReward::getCreateTime)
				.in(FxReward::getType,DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue(),DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue(),DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue())
				.eq(userTypeIdVo.getShopId()!=null,FxReward::getShopId,userTypeIdVo.getShopId())
				.eq(userTypeIdVo.getBrandId()!=null,FxReward::getBrandId,userTypeIdVo.getBrandId())
				.eq(userTypeIdVo.getCompanyId()!=null,FxReward::getCompanyId,userTypeIdVo.getCompanyId())
				.ge(timeVo.getStartTime()!=null,FxReward::getCreateTime,timeVo.getStartTime())
				.le(timeVo.getEndTime()!=null,FxReward::getCreateTime,timeVo.getEndTime()));

		vo.setSumInvite(list.stream().filter(o->o.getType()==DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue()).count());
		vo.setSumForward(list.stream().filter(o->o.getType()==DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue()).count());
		vo.setSumUse(list.stream().filter(o->o.getType()==DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue()).count());
		//根据时间分组
		Map<LocalDate,List<FxReward>> map = list.stream().collect(Collectors.groupingBy(o->o.getCreateTime().toLocalDate()));

		List<LocalDate> dateList = new ArrayList<>();
		List<Integer> inviteList = new ArrayList<>();
		List<Integer> forwardList = new ArrayList<>();
		List<Integer> useList = new ArrayList<>();
		map.forEach((k,v)->{
			//根据类型分组
			Map<Integer,List<FxReward>> tempMap = v.stream().collect(Collectors.groupingBy(FxReward::getType));
			/*FXRWVo.InnerFXRW innerFXRW = new FXRWVo.InnerFXRW();
			innerFXRW.setInvite(tempMap.getOrDefault(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue(),new ArrayList<>()).size());
			innerFXRW.setForward(tempMap.getOrDefault(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue(),new ArrayList<>()).size());
			innerFXRW.setUse(tempMap.getOrDefault(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue(),new ArrayList<>()).size());
			innerFXRW.setDate(k);
			vo.getList().add(innerFXRW);*/
			inviteList.add(tempMap.getOrDefault(DistributionTypeEnum.DISTRIBUTION_TYPE_0.getValue(),new ArrayList<>()).size());
			forwardList.add(tempMap.getOrDefault(DistributionTypeEnum.DISTRIBUTION_TYPE_1.getValue(),new ArrayList<>()).size());
			useList.add(tempMap.getOrDefault(DistributionTypeEnum.DISTRIBUTION_TYPE_2.getValue(),new ArrayList<>()).size());
			dateList.add(k);
		});

		vo.setDateList(dateList);
		vo.setInviteList(inviteList);
		vo.setForwardList(forwardList);
		vo.setUseList(useList);
		return vo;
	}

	@Override
	public List<FxRewardView> shopRewardTop(FxRewardView fxRewardView) {
		return this.baseMapper.shopRewardTop(fxRewardView);
	}

	@Override
	public List<FxRewardView> waiterRewardTop(FxRewardView fxRewardView) {
		List<FxRewardView> fxRewardViews = this.baseMapper.waiterRewardTop(fxRewardView);
		List<Long> ids = new ArrayList<>();
		for (FxRewardView rewardView : fxRewardViews) {
			ids.add(rewardView.getLoginId());
		}
		List<SysUser> sysUsers = remoteUserService.userByIds(ids);
		for (int i = 0; i < fxRewardViews.size(); i++) {
			for (int j = 0; j < sysUsers.size(); j++) {
				if(fxRewardViews.get(i).getLoginId().equals(Long.parseLong(sysUsers.get(j).getUserId()+""))){
					FxRewardView resultView = fxRewardViews.get(i);
					resultView.setUserName(sysUsers.get(j).getNickName());
					fxRewardViews.set(i,resultView);
				}
			}
		}
		return fxRewardViews;
	}

    @Override
    public void insert(FxReward fxReward) {
        this.baseMapper.insert(fxReward);
    }

	@Override
	public FxReward inviteReward(FxWaiterExt fxWaiterExtTemp, FxWaiterExt fxWaiterExt, Long waiterId, Long fyId) {
		//获取邀请金额规则
		BigDecimal inviteMoney = BigDecimal.ZERO;
		//平台总开关
		FxConfRewardBaseGlobel fxConfRewardBaseGlobel = fxConfRewardBaseGlobelService.list().get(0);

		if(0==fxConfRewardBaseGlobel.getSwitchs()&&0==fxConfRewardBaseGlobel.getInvite()){//开启

			inviteMoney = fxConfRewardBaseGlobel.getInviteMoney();
			//品牌的总开关
			FxConfRewardBase fxConfRewardBase = new FxConfRewardBase().selectOne(Wrappers.lambdaQuery(FxConfRewardBase.class).eq(FxConfRewardBase::getBrandId,fxWaiterExt.getBrandId()));
			if (fxConfRewardBase!=null&&fxConfRewardBase.getSwitchs()==0){//品牌开启
				ConfRewardShopVo temp = new ConfRewardShopVo();
				temp.setShopId(fxWaiterExt.getShopId());
				temp.setBrandId(fxWaiterExt.getBrandId());
				temp.setRuleType(0);//邀请
				temp = fxConfRewardService.getConfRewardShopVo(temp);
				if (temp!=null){//存在配置
					//如果平台的优惠大于品牌的就用平台的
					inviteMoney = inviteMoney.compareTo(temp.getBaseMoney())<0?temp.getBaseMoney():inviteMoney;
				}else {//不存在配置
				}
			}else {//品牌关闭
				inviteMoney = BigDecimal.ZERO;
			}
		}else {//平台关闭
		}

		//添加邀请奖励
		FxReward fxReward = new FxReward();
		fxReward.setBrandId(fxWaiterExt.getBrandId());
		fxReward.setShopId(fxWaiterExt.getShopId());
		fxReward.setCompanyId(fxWaiterExt.getCompanyId());
		fxReward.setWaiterId(waiterId);
		//如果新旧品牌不相等，就不加钱
		fxReward.setMoney(fxWaiterExt.getBrandId()!=fxWaiterExtTemp.getBrandId()?BigDecimal.ZERO:inviteMoney);
		fxReward.setType(0);//奖励类型0注册1转发2核销
		fxReward.setTatId(fyId);
		fxReward.setFyId(fyId);
		fxReward.setCreateUser(SecurityUtils.getPersonId());
		fxReward.setCreateTime(LocalDateTime.now());
		fxReward.insert();
		log.info("--------->添加邀请佣金：{}",fxReward);
		return fxReward;
	}


/*	public static void main(String[] args) {
		System.out.println(LocalDate.now().toString());
		System.out.println(LocalDateTime.now().toLocalDate());
		System.out.println(LocalDateTime.of(LocalDate.parse("2021-02-19"), LocalTime.now()));
		System.out.println(LocalDateTime.of(LocalDate.parse("2021-02-19"), LocalTime.now()));
		List<FxReward> list = new ArrayList<>();
		FxReward fxReward = new FxReward();
		fxReward.setId(1l);
		fxReward.setCreateTime(LocalDateTime.of(LocalDate.parse("2021-02-19"), LocalTime.parse("12:12:12")));
		FxReward fxReward1 = new FxReward();
		fxReward1.setId(2l);
		fxReward1.setCreateTime(LocalDateTime.of(LocalDate.parse("2021-02-18"), LocalTime.parse("12:12:11")));
		FxReward fxReward2 = new FxReward();
		fxReward2.setId(3l);
		fxReward2.setCreateTime(LocalDateTime.of(LocalDate.parse("2021-02-17"), LocalTime.parse("12:12:11")));
		FxReward fxReward3 = new FxReward();
		fxReward3.setId(4l);
		fxReward3.setCreateTime(LocalDateTime.of(LocalDate.parse("2021-02-17"), LocalTime.now()));
		list.add(fxReward);
		list.add(fxReward1);
		list.add(fxReward2);
		list.add(fxReward3);
		Map<Long,LocalDateTime> shopMap = list.stream().collect(Collectors.toMap(FxReward::getId,o->o.getCreateTime()));
		System.out.println(JSONUtil.toJsonStr(shopMap));
		Map<LocalDate,List<FxReward>> map = list.stream().collect(Collectors.groupingBy(o->o.getCreateTime().toLocalDate()));
		System.out.println(JSONUtil.toJsonStr(map));

		System.out.println(new CnShop().getName());


		List<CouponUseTopVo> voList = new ArrayList<>();
		for (int i=0;i<6;i++) {
			CouponUseTopVo vo = new CouponUseTopVo();
			vo.setMoney(i+"");
			voList.add(vo);
		}

		List<CouponUseTopVo> voListTempTop = voList.stream().sorted(Comparator.comparing(CouponUseTopVo::getMoney).reversed()).limit(10).collect(Collectors.toList());
		System.out.println(JSONUtil.toJsonStr(voListTempTop));


	}*/

	/**
	 * 获取服务员的佣金收益 统计
	 *
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public FxRewardVo getSumByMoneyAndFind(FxRewardVo fxRewardVo) {
		return fxRewardMapper.getSumByMoneyAndFind(fxRewardVo);
	}

	/**
	 * 获取服务员 佣金收益统计下边的饭友列表
	 *
	 * @param page
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public IPage<FxRewardVo> getCommissionRevenuesFanYouCount(Page page, FxRewardVo fxRewardVo) {
		return fxRewardMapper.getCommissionRevenuesFanYouCount(page, fxRewardVo);
	}

	/**
	 * 获取服务员 收益明细 统计信息
	 *
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public FxRewardVo getCommissionRevenuesDetailed(FxRewardVo fxRewardVo) {
		return fxRewardMapper.getCommissionRevenuesDetailed(fxRewardVo);
	}

	/**
	 * 获取服务员 收益明细 的列表
	 *
	 * @param page
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public IPage<FxRewardVo> getCommissionRevenuesFanYouDetailedList(Page page, FxRewardVo fxRewardVo) {
		return fxRewardMapper.getCommissionRevenuesFanYouDetailedList(page, fxRewardVo);
	}

	/**
	 * 获取服务员 收益明细 的类型 统计
	 *
	 * @param fxRewardVo
	 * @return
	 */
	@Override
	public FxRewardVo getCommissionRevenuesFanYouDetailedCount(FxRewardVo fxRewardVo) {
		return fxRewardMapper.getCommissionRevenuesFanYouDetailedCount(fxRewardVo);
	}
}
